<template>

  <div class="box"><router-link to="/My">
    <van-nav-bar
  title="修改密码"
  left-arrow
/></router-link>
<!-- 手机号 -->
<van-form @submit="onSubmit" ref="code">
  <van-field
    v-model="username"
    name="username"
    label="账号"
    placeholder="请输入账号"
    :rules="[{ required: true, message: '请填写账号' },{pattern: /\d{11}/,message: '请输入正确手机号格式'}]"
  />
  <van-field
    v-model="oldpassword"
    type="oldpassword"
    name="oldpassword"
    label="旧密码"
    placeholder="请输入旧密码"
    :rules="[{ required: true, message: '请填写密码'}]"
  />
 <van-field
    v-model="newpassword"
    type="newpassword"
    name="newpassword"
    label="新密码"
    placeholder="请输入新密码"
    :rules="[{ required: true, message: '请填写密码'}]"
  />
  
  
  
  <div style="margin: 16px;">
    <van-button round block type="info" native-type="submit" color="pink" @click="enroll">注册</van-button>
  </div>
</van-form>
  </div>
</template>

<script>
import { Toast } from 'vant';
export default {
  data(){
      return{
          sms:'',
          tel: '',
          btn:'60',
          username:'',
          oldpassword: '',
          newpassword: '',
      }
  },
// 发送验证码
methods: {
    security(){
      this.$http.post('/user/sendSms',{
              mobile:this.username,
              type:'register'
            })
            .then(res=>{
              console.log(res);
            })
      this.$refs.code.validate('username')
      .then(res=>{
      console.log(res)
      }).catch(res=>{
      console.log(res);
      })
         
    },
    enroll(){
        // 旧密码接口
          let use =localStorage.getItem("Token")
         let pos = JSON.parse(use);
         console.log(pos.password);
        // uid 接口
        let users =localStorage.getItem("user")
         let poss = JSON.parse(users);
         console.log(poss.uid);
        this.$http.post('/user/updatePwd',{
              username:this.username,
               oldpassword:pos.password,
               newpassword:this.newpassword,
               uid:poss.uid
            })
            .then(res=>{
              console.log(res);
              this.$router.push('/My')
            })
    },
    onSubmit(values) {
      console.log('submit', values);
    },
    onClickLeft() {
      Toast('返回');
    },
    onClickRight() {
      Toast('按钮');
    },
  },
}
</script>

<style lang="less" scoped>

  .box{
    height: 100vh;
        position: relative;
        z-index: 9;
        background-color: #fff;

}
.shouji{
  display: flex;
}
.shouji .iconfont {
  display: inline-block;
  margin-right: -10px ;
  z-index: 1;
  margin-left: 15px;
  height: 50px;
  line-height: 40px;
}
.boder{
  margin-right:10px ; 
}
.auth{
  display: flex;
}
.auth .iconfont {
   display: inline-block;
  margin-right: -10px ;
  z-index: 1;
  margin-left: 15px;
  height: 50px;
  line-height: 48px;
 
}
.register{
  
    margin-top: 50px ;
    background-color: pink;
    width: 300px;
    height: 50px;
}
.login{
  float: left;
  margin-left: 20px;
}
</style>